<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<title>手机号码验证</title>

    <script type="text/javascript">
        var APPVERSION = Date.now();
		document.write('<link rel="stylesheet" href=\"\/aigo\/css\/reset.css?v='+APPVERSION+'\">');
        document.write('<link rel="stylesheet" href=\"\/aigo\/css\/login.css?v='+APPVERSION+'\">');
    </script>

</head>
<body>
<div class="main-view">
	<div class="zz"></div>
	<span class="warnign">手机号码格式错误</span>
	<div class="inputlogin">
		<i class="icn_mobe"></i>
		<div class="indiv">
			<input type="text" placeholder="请输入您的手机号码" id="phone" name="phone"/>
			<div class="sendy" id="sendy">发送短信验证码</div>
		</div>
	</div>
	<div class="inputlogin yanz">
		<i class="icn_yan"></i>
		<div class="indiv">
			<input type="text" placeholder="请输入短信验证码" id="yan" name="yan"/>
		</div>
	</div>
	<div class="inputlogin">
		<i class="icn_key"></i>
		<div class="indiv">
			<input type="password" placeholder="请输入密码" id="pwd" name="pwd"/>
			<i class="passwd" id="passwd"></i>
		</div>
	</div>
	<div class="btn" id="sub">登录</div>
	<div class="btn" id="reg">注册</div>
	<span class="xbtn" id="regbtn">没有账号请先注册！</span>
	<span class="xbtn" id="subbtn">已有账号，直接登录！</span>
</div>
<script>
	document.write('<script src=\"\/aigo\/js\/jqury.js?v=' + APPVERSION + '\"><\/script>')
	document.write('<script src=\"\/aigo\/js\/fastclick.js?v=' + APPVERSION + '\"><\/script>')
</script>
<script type="text/javascript">
$(function(){
	$("#reg").on('click', function(e) {
		if ($("#phone").val() == "" || $("#pwd").val() == "") {
			alert("用户名和密码不能为空！");
		} else {
			console.log("注册开始");
			$.post("/wx/wxreg?v=" + Math.random(), {
				username : $("#phone").val(),
				vcode : $("#yan").val(),
				password : $("#pwd").val()
			}, function(data) {
				if (data.msg == '1') {
					alert("注册成功请登录！");
						$(".inputlogin .indiv .sendy").hide();
 						$(".inputlogin.yanz").hide();
 						$("#sub").show();
 						$("#reg").hide();
					//window.location = "/wx/device";
				} else {
					alert(data.msg);
				}
			});
		}
	});
	$("#sub").on('click', function(e) {
		if ($("#phone").val() == "" || $("#pwd").val() == "") {
			alert("用户名和密码不能为空！");
		} else {
			$.post("/wx/wxlogin?v=" + Math.random(), {
				username : $("#phone").val(),
				password : $("#pwd").val()
			}, function(data) {
				if (data.msg == 'success') {
					window.location = "/wx/device";
				} else {
					alert(data.msg);
				}
			});
		}
	})
})
$( document ).ready(function() {
	$("#passwd").on('click',function(){
		if($(this).attr("class") == "passwd"){
			$(this).removeClass("passwd");
			$("#pwd").attr("type","text");
		}else{
			$(this).addClass("passwd");
			$("#pwd").attr("type","password");
		}
	});
	$("#regbtn").on('click',function(){
		$(".inputlogin .indiv .sendy").show();
		$(".inputlogin.yanz").show();
		$("#sub").hide();
		$("#reg").show();
		$("#subbtn").show();
		$(this).hide();
	});
	$("#subbtn").on('click',function(){
		$(".inputlogin .indiv .sendy").hide();
		$(".inputlogin.yanz").hide();
		$("#sub").show();
		$("#reg").hide();
		$("#regbtn").show();
		$(this).hide();
	});
	$('#phone').blur(function(){
		var ret = false;
		var phoneval = $("#phone").val();
		var ret = checkMobile(phoneval);
		if(!ret){
			$(this).focus();
		}else{
			$.post("/wx/UserNameExist?v=" + Math.random(), {
 				username : $("#phone").val()
 			}, function(data) {
 					if(data.resu){
 						$(".inputlogin .indiv .sendy").hide();
 						$(".inputlogin.yanz").hide();
 						$("#sub").show();
 						$("#reg").hide();
 						
 					}else{
 						alert("不存在,请先注册");
 						$(".inputlogin .indiv .sendy").show();
 						$(".inputlogin.yanz").show();
 						$("#sub").hide();
 						$("#reg").show();
 					}
 				})
		}
	})
	/* $('#yan').blur(function(){ 
		yanzheng();
	}) */
})
/* 	function yanzheng(){
	var yanmumber = $("#yan").val();
	if(yanss!=yanmumber){
		$(".zz").show();
		$(".warnign").text("验证码错误");
		$(".warnign").css({"height":"40px"});
		$(this).focus();
		setTimeout(function() {
			$(".zz").hide();
			$(".warnign").text("");
			$(".warnign").css({"height":"0px"});
		}, 2000);
	}
} */
	function checkMobile(str) {
		var re = /^1\d{10}$/
		if (re.test(str)) {
			$(".warnign").text("");
			$(".warnign").css({"height":"0px"});
			return true;
		} else {
			$(".zz").show();
			$(".warnign").text("手机号格式错误");
			$(".warnign").css({"height":"40px"});
			setTimeout(function() {
				$(".zz").hide();
				$(".warnign").text("");
				$(".warnign").css({"height":"0px"});
			}, 3000);
			return false;
		}
	}
    var sleep = 60, interval = null;
    window.onload = function ()
    {
        var btn = document.getElementById ('sendy');
        btn.onclick = function ()
        {
        	 if ($("#phone").val() == "") {
     			alert("用户名不能为空！");
     		} else {
     			$.post("/wx/yan?v=" + Math.random(), {
     				username : $("#phone").val()
     			}, function(data) {
     				if(data.vocod=="1"){
     					alert("发送成功！");
     				}else{
     					alert(data.vocod);
     				}
     				})
            if (!interval)
            {
                this.style.backgroundColor = 'rgb(243, 182, 182)';
                this.disabled = "disabled";
                this.style.cursor = "wait";
                this.innerHTML = "重新发送 (" + sleep-- + ")";
                interval = setInterval (function ()
                {
                    if (sleep == 0)
                    {
                        if (!!interval)
                        {
                            clearInterval (interval);
                            interval = null;
                            sleep = 60;
                            btn.style.cursor = "pointer";
                            btn.removeAttribute ('disabled');
                            btn.innerHTML = "发送短信验证码";
                            btn.style.backgroundColor = '';
                        }
                        return false;
                    }
                    btn.innerHTML = "重新发送 (" + sleep-- + ")";
                }, 1000);
            }
     		}
        }
    }

</script>
</body>
</html>